package com.sky.controller.admin;

import com.sky.dto.AppealDTO;
import com.sky.dto.AppealPageQueryDTO;
import com.sky.entity.Appeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AppealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/appeal")
@Api(tags = "申诉相关接口")
@Slf4j
public class AppealController {
    @Autowired
    private AppealService appealservice;

    /**
     * 分页查询
     * @param pageQuery
     * @return
     */
    @RequiresPermissions("管理员")
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(AppealPageQueryDTO pageQuery) {
        PageResult pageResult = appealservice.pageQuery(pageQuery);
        return Result.success(pageResult);
    }
    //根据id查找申诉
    @RequiresRoles(value={"管理员","普通用户"},logical = Logical.OR)
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找申诉")
    public Result<Appeal> getById(@PathVariable Long id) {
        return Result.success(appealservice.getById(id));
    }
    //申诉处理
    @RequiresRoles("管理员")
    @PostMapping()
    @ApiOperation(value = "申诉处理")
    public Result process(@RequestBody AppealDTO appealDTO) {
        appealservice.process(appealDTO);
        return Result.success();
    }
}
